import axios, { AxiosResponse } from "axios";
import { useStore } from "vuex";

const store = useStore();
const axiosInstance = axios.create({
  baseURL: "http://localhost:3000",
});
export const getList: <T>({
  name,
}: {
  name: string;
}) => Promise<AxiosResponse<Array<T>>> = ({ name }) =>
  axiosInstance.post("/getList", {
    name,
  });

export const getRoomList = (): Promise<AxiosResponse> =>
  axiosInstance.get("/roomManage/getRoomList");

export const insertRoom = (payload: any) =>
  axiosInstance.post("/roomManage/insertRoom", payload);

const baseApi = (serviceName: string) => {
  return {
    list(payload: any) {
      return axiosInstance.post(`/${serviceName}/list`, payload);
    },
    delete(payload: any) {
      return axiosInstance.post(`/${serviceName}/delete`, payload);
    },
    update(payload: any) {
      return axiosInstance.post(`/${serviceName}/update`, payload);
    },
    get(payload: any) {
      return axiosInstance.post(`/${serviceName}/get`, payload);
    },
  };
};
export const roomType = {
  ...baseApi("RoomType"),
};
export const floor = {
  ...baseApi("Floor"),
};
export const roomTag = {
  ...baseApi("RoomTag"),
};
export const deposit = {
  ...baseApi("Deposit"),
};
export const discount = {
  ...baseApi("Discount"),
};
export const roomPackage = {
  ...baseApi("RoomPackage"),
};
export const user = {
  ...baseApi("User"),
};
export const admin = {
  ...baseApi("Admin"),
};
export const book = {
  ...baseApi("Book"),
};
export const bookOrder = {
  ...baseApi("BookOrder"),
};
export const roomBook = {
  ...baseApi("RoomBook"),
};
export const checkInRecord = {
  ...baseApi("CheckInRecord"),
};
export const checkInInfo = {
  ...baseApi("CheckInInfo"),
};
export const supplier = {
  ...baseApi("Supplier"),
};
export const production = {
  ...baseApi("Production"),
};
export const productionSupplier = {
  ...baseApi("ProductionSupplier"),
};
export const vip = {
  ...baseApi("Vip"),
};
export const userVip = {
  ...baseApi("UserVip"),
};
export const pay = {
  ...baseApi("Pay"),
};
